<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>天天生鲜-首页</title>
<link rel="short icon" href="images/copylogo.png">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/foot.css">
</head>

<body >
	<!-- 头部  -->
	<div class="header_con">
    	<div class="header">
    		<div class="welcome fl">欢迎来到天天生鲜</div>
    		<div class="fr" id="stu_name">
            	
             </div>  
    	</div>
    </div>
    
     <!-- 搜素框 -->
     <div class="search_bar clearfix">
     		<a href="index.html" class="logo fl"><img src="images/logo.png"></a>
     		<div class="search_con fl">
            	<form>
                    <input type="text" class="input_text fl" name="key_words" placeholder="搜索商品" id="inp">
                    <input type="button" class="input_btn fr"  value="搜索" onclick="find()">
                </form>
            </div>
     		<div class="guest_cart fr">
            	<a href="front/page/cart.html" class="cart_name fl">我的购物车</a>
                <div class="goods_count fl" id="show_count">0</div>
            </div>
     </div>

    <!-- 商品分类 -->
    <div class="navbar_con">
    	<div class="navbar">
    		<h1 class="fl">全商品分类</h1>
    		<ul class="navlist fl">
    			<li><a href="">首页</a></li>
                <li class="interval">|</li>
                <li><a href="">手机生鲜</a></li>
                <li class="interval">|</li>
                <li><a href="">抽奖</a></li>
    		</ul>
    	</div>
    </div>
    
    <!-- 导航栏 -->
    <div class="center_con clearfix">
        <div class="subnav fl">
            <ul id="typeinfo">
               
            </ul>
        </div>
        <div class="slide fl">
            <ul class="slide_pics">
                <li><a href="" class=""><img src="images/slide.jpg" alt="幻灯片"></a></li>
                <li><a href="" class=""><img src="images/slide02.jpg" alt="幻灯片"></a></li>
                <li><a href="" class=""><img src="images/slide03.jpg" alt="幻灯片"></a></li>
                <li><a href="" class=""><img src="images/slide04.jpg" alt="幻灯片"></a></li>
            </ul>
            <div class="prev"></div>
            <div class="next"></div>
            <ul class="points"></ul>
        </div>
        <div class="adv fl">
            <a href=""><img src="images/adv01.jpg" alt="清凉一夏"></a>
            <a href=""><img src="images/adv02.jpg" alt="盛夏尝鲜"></a>
        </div>
    </div>
    
    <!-- 商品展示 -->
    <div id="goodsinfo">
    
    </div>
   
    
    <!-- 版权所有 -->
    <div class="footer">
    	<div class="foot_link">
        	<a href="#">关于我们</a> <span> | </span>
            <a href="#">联系我们</a> <span> | </span>
            <a href="#">招聘广告</a> <span> | </span>
            <a href="#">友情链接</a>
        </div>
    	<p>CopyRight &copy; 2019 嘟嘟嘟水果欢迎你的到来 All Rights Reserverd</p>
        <p>电话： -1</p>
    </div>
    
    <!--  注意引入顺序 -->
	<script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/jquery-ui.min.js"></script>
    <script src="js/slide.js"></script>
    <script>   	
    	<!--添加的 -->
		$.post("menberInfo/checkLogin", null , function(data){
			var str ='';
			
			if(!data.code){			
				str+='<div class="login_info fl">';
				str+='欢迎：<em>'+data.nickName+'</em>';
				str+='</div> ';	
				geCarNnm(data.mno);
			} else {			
				str+='<div class="login_btn fl">';
				str+='<a href="login.html">登录</a>';
				str+='<span> | </span>';
				str+='<a href="register.html">注册</a>';
				str+='</div>';
			}
			str+='<div class="user_link fl">';
			str+='<span> | </span>';
			str+='<a href="front/page/user.html">用户中心</a>';
			str+='<span> | </span>';
			str+='<a href="front/page/cart.html">我的购物车</a>';
			str+='<span> | </span>';
			str+=' <a href="front/page/order.html">我的订单</a>  </div> ';
	    	$("#stu_name").html(str);
		}, "json");
  
	    $.post("goodsInfo/findAll", null , function(data){
	    	 var tno = data[0].tno;
	    	 var str='';
	    	 var num=0;
	    	 var typestr='';
	    	 var arr2=["fruit","seafood","meet","egg","vegetables","ice"];	    	 
	    	 for(var i=0;i<data.length;i++){ 
	    		 if(data[i].tno == tno){
	    			 typestr+='<li><a href="#model0'+(i+1)+'" class="'+arr2[i]+'">'+data[i].tname +'</a></li>';
	    			 
	    			 str+='<div class="list_model">';
		    		 str+='<div class="list_title clearfix">';
		    		 str+='	<h3 class="fl" id="model0'+(i+1)+'">'+data[i].tname+'</h3>';
		    		 str+='<div class="subtitle fl">';
		    		 str+='<span>|</span>';
		    		 for(var j=0;j<data.length;j++){
		    			 if(data[j].tno == tno && num<4){
		    				 str+='<a href="">'+data[j].gname+'</a>';
		    				 num++; 
		    			 }
		    		 }
		    		 num=0; 
		    		 str+=' </div>   <a href="goods.html?tno='+tno+'" class="goods_more fr" id="fruit_more">查看更多</a>';
		    		 str+=' </div> <div class="goods_con clearfix">';
		    		 str+='<div class="goods_banner fl"><img src="'+data[i].pic+'"></div>';
		    		 str+='	<ul class="goods_list fl">';
		    		 for(var j=0;j<data.length;j++){
		    			 if(data[j].tno == tno && num<4){
		    				 str+='<li> <h4><a href="details.html?gno='+data[j].gno+'">'+data[j].gname+'</a></h4>';
		    				 str+='<a href="details.html?gno='+data[j].gno+'"><img src="'+data[j].pics+'"></a>';
		    				 str+='<div class="prize">￥ '+data[j].price+'</div> </li>';
				    		 num++; 
		    			 }		    			 
		    		 }
		    		 num=0;
		    		 str+='</ul>  </div>  </div>';	
		    		 tno++;
	    		 }
	    	 }
	    	 $("#typeinfo").html(typestr);	    	 
	    	 $("#goodsinfo").html(str);
	    }, "json");
	    

	    
		//获取url地址栏
    	$(function () {
			if(location.href.split("?").length>=2){
				//容错处理，不这样做的话，如果没有参数，那么我们的服务器就会直接报错		
				  var str=location.href.replace('http://localhost:8080/fresh/index.html?charset=utf-8&','');  
				  var ono=str.split("&")[0].split("=")[1];
				  			
					$.post("orderInfo/setStatus", {ono:ono},function(data){
						if(data>0){
							location.href="index.html"
						}
					},"text");	
				}
			})
			
		
		
		function geCarNnm(mno){
			$.post("cartInfo/finds", {mno:mno}, function(data){
				var numStr=data.length;		    	
				$("#show_count").html(numStr);
			},"json");	
		}

		function find(){
			var str=$("#inp").val();
			$.post("goodsInfo/find",{str:str},function(data){
				console.log(data);
				if(data==null){
					alert("抱歉,没有该商品...");
					console.log("抱歉,没有该商品...");
				}else{					
					location.href="details.html?gno="+data.gno;
				}
			},"json");
		}
		 
    </script>
</body>
</html>
